<style>
.webboard-button{padding:10px 0;}
.pagination{float:right;}
.webboard-list{width:100%;}
.webboard-list tr th{padding:10px 5px;text-align:left;font-size:12px;font-weight:bold;background:#E5EDF2;}
.webboard-list tr td{padding:10px 5px;border:1px dotted #ddd;border-left:none;border-right:none;vertical-align:middle;}
.webboard-list .small{width:105px;font-size:12px;}
.text-info{color:#888;font-size:11px;}
a:link.edit,a:visited.edit{color:green;font-size:13px;}
a:link.delete,a:visited.delete{color:red;font-size:13px;}
</style>
<h2><span><a href="pages/home">หน้าแรก</a> &raquo; เว็บบอร์ด</span></h2>
	<div id="content-data">
		<div id="module-webboard" >
			
			<div class="webboard-button">
				<a href="webboard/topics/form">ตั้งกระทู้</a>
				<?php echo $topics->pagination()?>
				<div class="clear"></div>
			</div>	
			<table class="webboard-list">
				<tr class="head">
					<th></th>
					<th>หัวข้อกระทู้</th>
					<th>โดย</th>
					<th>ตอบ/ดู</th>
					<th>โพสล่าสุด</th>
				</tr>
				<?php foreach($topics as $topic):?>
				<tr>
					<td><?php echo anchor('webboard/topics/view/'.$topic->id,'<span class="icon icon-comments"></span>')?></td>
					<td class="title">
						<?php echo anchor('webboard/topics/view/'.$topic->id,$topic->title)?>
						<?php 
						if(is_login() && ( user()->level_id < 3 OR user()->post->get_by_id($topic->id)->id))
						{
							echo '<br />'.anchor('webboard/topics/form/'.$topic->id,'แก้ไข','class="edit"');
							echo ' - '.anchor('webboard/topics/delete/'.$topic->id,'ลบ','class="delete" onclick="return confirm(\'ยืนยันการลบ\')"');
						}
						?>
					</td>
					<td class="small"><?php echo $topic->user->display.br().'<span class="text-info">'.mysql_to_th($topic->created).'</span>'?></td>
					<td class="small"><?php echo $topic->reply->get()->result_count()?>/<?php echo number_format($topic->counter)?></td>
					<td class="small">
						<?php 
							$last = $topic->where('id',$topic->id)->or_where('topic_id',$topic->id)->order_by('id','desc')->get(); 
							echo ($last->user_id) ? $last->user->display : $last->author;
							echo '<br /><span class="text-info">'.mysql_to_relative($last->created).'</span>';
						?>
					</td>
				</tr>
				<?php endforeach?>
			</table>
			<div class="webboard-button">
				<a href="webboard/topics/form">ตั้งกระทู้</a>
				<?php echo $topics->pagination()?>
				<div class="clear"></div>
			</div>	
		</div>
		<div class="clear"></div>
	</div>
